{% extends "base.html" %}

{% block pageheader %}
{% if 'add_record' in request.path %}
Add
{% elif 'edit_record' in request.path %}
Edit
{% else %}
Unknown Action!
{% endif %}
record in {{ form.zone_name.value }}
{% endblock pageheader %}

{% block body %}

<form class="form-horizontal" action="{% url "add_record" dns_server=dns_server zone_name=form.zone_name.value %}" method="POST">{% csrf_token %}
  <legend>Create Record</legend>

  <div class="form-group{% if form.dns_server.errors %} has-error{% endif %}">
    <label for="dns_server" class="col-sm-3 control-label">DNS Server:</label>
    <div class="col-sm-5 col-md-4">
      <input id="dns_server" name="dns_server" type="text" class="form-control" value="{{dns_server.hostname}}" readonly="readonly" />
    </div>
    {% if form.dns_server.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.dns_server.errors|stringformat:"s"|striptags }}
        {% if form.dns_server.value %}Previous Value: {{ form.dns_server.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.record_name.errors %} has-error{% endif %}">
    <label for="record_name" class="col-sm-3 control-label">Record Name:</label>
    <div class="col-sm-5 col-md-4">
      <div class="input-group">
        <input id="record_name" name="record_name" type="text" class="form-control"{% if form.record_name.value %} value="{{ form.record_name.value }}" readonly="readonly"{% endif %}/>
        <span class="input-group-addon">.{{ form.zone_name.value }}</span>
        <input type="hidden" name="zone_name" value="{{ form.zone_name.value }}" />
      </div>
    </div>
    {% if form.record_name.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger form-control-static">
        {{ form.record_name.errors|stringformat:"s"|striptags }}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.record_type.errors %} has-error{% endif %}">
    <label for="record_type" class="col-sm-3 control-label">Record Type:</label>
    <div class="col-sm-5 col-md-4">
      <select id="record_type" name="record_type" class="form-control">
      {% if "in-addr.arpa" not in form.zone_name.value and "ip6.arpa" not in form.zone_name.value %}
          {% for choice in form.record_type %}
            {{ choice }}
          {% endfor %}
      {% else %}
        <option value="PTR">PTR</option>
      {% endif %}
      </select>
    </div>
    {% if form.record_type.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.record_type.errors|stringformat:"s"|striptags }}
        {% if form.record_type.value %} Previous Value: {{ form.record_type.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.record_data.errors %} has-error{% endif %}">
    <label for="record_data" class="col-sm-3 control-label">Record Data:</label>
    <div class="col-sm-5 col-md-4">
      <input id="record_data" name="record_data" type="text" class="form-control"{% if form.record_data.value %} value="{{ form.record_data.value }}"{% endif %} />
    </div>
    {% if form.record_data.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.record_data.errors|stringformat:"s"|striptags }}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.ttl.errors %} has-error{% endif %}">
    <label for="ttl" class="col-sm-3 control-label">TTL: </label>
    <div class="col-sm-5 col-md-4">
      <select id="ttl" name="ttl" class="form-control">
        {% for choice in form.ttl %}
          {{ choice }}
        {% endfor %}
      </select>
    </div>
    {% if form.ttl.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.ttl.errors|stringformat:"s"|striptags }}
        {% if form.ttl.value %} Previous choice: {{ form.ttl.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  {% if "in-addr.arpa" not in form.zone_name.value and "ip.arpa" not in form.zone_name.value %}
  <div class="form-group">
    <label for="create_reverse" class="col-sm-3 control-label checkbox">Create Reverse Record (PTR):</label>
    <div class="col-sm-5 col-md-4">
      <input type="checkbox" id="create_reverse" name="create_reverse" value="True" />
    </div>
  </div>
  {% endif %}

  <div class="form-group{% if form.key_name.errors %} has-error{% endif %}">
    <label for="key_name" class="col-sm-3 control-label">TSIG Key:</label>
    <div class="col-sm-5 col-md-4">
      <select id="key_name" name="key_name" class="form-control">
        {% for choice in form.key_name %}
          {{ choice }}
        {% endfor %}
      </select>
    </div>
    {% if form.key_name.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.key_name.errors|stringformat:"s"|striptags }}
        {% if form.key_name.value %} Previous choice: {{ form.key_name.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group">
    <div class="col-sm-3"></div>
    <div class="col-sm-5 col-md-4">
      <button type="submit" class="btn btn-default">Save Changes</button>
      <a href="{% url "zone_list" dns_server=dns_server zone_name=form.zone_name.value %}" class="btn btn-warning">Cancel</a>
    </div>
  </div>
</form>
{% endblock body %}
